import React, { ReactElement } from 'react';
import { View, StyleSheet } from "react-native";
import SSwiper, { SwiperProps as SSwiperProps } from 'react-native-swiper';
import { dpw200 } from "../constants";


interface SwiperProps extends SSwiperProps {
    data: Record<string, any>[],
    renderItem: (_p: Record<string, any>) => ReactElement
}

export const Swiper = (props: SwiperProps) => {
    const { data, renderItem, autoplay = true, height, ...rest } = props;
    return (
        <View style={height ? { height } : styles.container}>
            <SSwiper autoplay={autoplay} {...rest}>
                {Array.isArray(data) ? data.map((it) => renderItem(it)) : null}
            </SSwiper>
        </View>
    ) 
}
 
const styles = StyleSheet.create({
  container: {
    height: dpw200, 
  },
});
